package com.ruoyi.project.punch.service.impl;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.Date;
import java.util.Formatter;
import java.util.List;

import com.ruoyi.common.exception.base.BaseException;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.punch.mapper.PunchRecordMapper;
import com.ruoyi.project.punch.domain.PunchRecord;
import com.ruoyi.project.punch.service.IPunchRecordService;

/**
 * 打卡记录Service业务层处理
 * 
 * @author zhf
 * @date 2022-11-05
 */
@Service
public class PunchRecordServiceImpl implements IPunchRecordService 
{
    @Autowired
    private PunchRecordMapper punchRecordMapper;

    /**
     * 查询打卡记录
     * 
     * @param id 打卡记录主键
     * @return 打卡记录
     */
    @Override
    public PunchRecord selectPunchRecordById(Long id)
    {
        return punchRecordMapper.selectPunchRecordById(id);
    }

    /**
     * 查询打卡记录列表
     * 
     * @param punchRecord 打卡记录
     * @return 打卡记录
     */
    @Override
    public List<PunchRecord> selectPunchRecordList(PunchRecord punchRecord)
    {
        return punchRecordMapper.selectPunchRecordList(punchRecord);
    }

    /**
     * 新增打卡记录
     * 
     * @param punchRecord 打卡记录
     * @return 结果
     */
    @Override
    public int insertPunchRecord(PunchRecord punchRecord)
    {
        punchRecord.setCreateTime(DateUtils.getNowDate());
        PunchRecord punchRecord1 = new PunchRecord();
        punchRecord1.setPunchTime(punchRecord.getPunchTime());
        punchRecord1.setShift(punchRecord.getShift());
        punchRecord1.setMemberId(punchRecord.getMemberId());
        punchRecord1.setPunchType(punchRecord.getPunchType());
        List<PunchRecord> list1 = punchRecordMapper.selectPunchRecordList(punchRecord1);
        if(list1.size() > 0) {
            throw new BaseException("打卡记录已存在");
        }
        return punchRecordMapper.insertPunchRecord(punchRecord);
    }

    /**W
     * 修改打卡记录
     * 
     * @param punchRecord 打卡记录
     * @return 结果
     */
    @Override
    public int updatePunchRecord(PunchRecord punchRecord)
    {
        punchRecord.setUpdateTime(DateUtils.getNowDate());
        return punchRecordMapper.updatePunchRecord(punchRecord);
    }

    /**
     * 批量删除打卡记录
     * 
     * @param ids 需要删除的打卡记录主键
     * @return 结果
     */
    @Override
    public int deletePunchRecordByIds(Long[] ids)
    {
        return punchRecordMapper.deletePunchRecordByIds(ids);
    }

    /**
     * 删除打卡记录信息
     * 
     * @param id 打卡记录主键
     * @return 结果
     */
    @Override
    public int deletePunchRecordById(Long id)
    {
        return punchRecordMapper.deletePunchRecordById(id);
    }
}
